#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File: log_config.py
# Date: 2025/4/17
# Author: zhang shuirong

import logging
from logging.handlers import RotatingFileHandler
import os

# 创建日志目录
LOG_DIR = "logs"
if not os.path.exists(LOG_DIR):
    os.makedirs(LOG_DIR)

# 配置日志系统
log_file_path = os.path.join(LOG_DIR, "api_service.log")
logger = logging.getLogger("API_LOGGER")
logger.setLevel(logging.INFO)

file_handler = RotatingFileHandler(log_file_path, maxBytes=10 * 1024 * 1024, backupCount=10, encoding='utf-8')
file_handler.setLevel(logging.INFO)

# 自定义时间格式为中文
formatter = logging.Formatter(
    "%(asctime)s - %(levelname)s - %(message)s",
    datefmt="%Y年%m月%d日 %H时%M分%S秒"
)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)


def get_logger():
    return logger
